package com.fc.service.impl

import java.util.List;

import org.hibernate.Criteria
import org.hibernate.criterion.Projections
import org.hibernate.criterion.Restrictions
import org.springframework.stereotype.Repository
import org.springframework.transaction.annotation.Transactional;

import com.fc.service.FoodGroupService
import com.fc.entities.FoodGroup

/**
 * 
 * @author aacs
 *
 */
@Repository("foodGroupService")
@Transactional
class FoodGroupServiceImpl extends BaseServiceImpl<FoodGroup> implements FoodGroupService {
	@Override 
	List<String> getAllNames() {
		Criteria criteria = currentSession().createCriteria(FoodGroup.class, "foodgroup").setProjection(Projections.projectionList().add(Projections.property("foodgroup.name")));
		return criteria.list();
	}
	
	FoodGroup findByName(String name) {
		Criteria criteria = currentSession().createCriteria(FoodGroup.class);
		FoodGroup fg = (FoodGroup) criteria.add(Restrictions.eq("name", name)).uniqueResult();
		return fg;
	}

	@Override
	List<FoodGroup> findAll() {
		findAll(FoodGroup.class)
	}
}
